using System;
using System.Text;

namespace Randomize.Core.Generators
{
    public class StringGenerator : Generator<string>, IStringGenerator
    {
        private const int AsciiStart = 48;

        private const int AsciiEnd = 123;

        private const int DefaultLength = 50;

        public int? Length { get; set; }

        public StringGenerator(Random random)
            : base(random)
        {
        }

        protected override string GenerateRandomValue()
        {
            int length = this.Length ?? DefaultLength;

            var buffer = new StringBuilder(length);
            for (int i = 0; i < length; i++)
            {
                buffer.Append(Convert.ToChar(this.RandomInstance.Next(AsciiStart, AsciiEnd)));
            }

            return buffer.ToString();
        }
    }
}